package bold.deposit;


import bold.deposit.interception.NoAuthorize;
import bold.deposit.useful.Result;
import bold.storage.component.BaseDao;
import bold.storage.core.RecordList;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

@RestController
@RequestMapping("resources")
public class ResourcesController extends BaseDao {

    @RequestMapping(value = "tree")
    @NoAuthorize
    public Result tree() throws SQLException {
        RecordList records = query("resources").where("state", "1").orderAsc("sort").recordList();
        if (records.isEmpty()) {
            return new Result(404);
        }
        return new Result(TreeUtil.toTree(records));
    }
}
